package cn.org.eshow.webapp.action;

import cn.org.eshow.bean.query.OrderStepQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.model.OrderStep;
import cn.org.eshow.service.OrderStepManager;
import cn.org.eshow.util.PageUtil;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Results({@Result(name = "input", location = "add"),
        @Result(name = "list", type = "redirect", location = ""),
        @Result(name = "success", type = "redirect", location = "view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"list", "search",  "view"})
public class OrderStepAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private OrderStepManager orderStepManager;

    private List<OrderStep> orderSteps=new ArrayList<OrderStep>();
    private OrderStep orderStep=new OrderStep();
    private OrderStepQuery query = new OrderStepQuery();

    /**
     * @return
     */
    public String list() {
        orderSteps = orderStepManager.list(query);
        return LIST;
    }

    /**
     * @return
     */
    public String search() {
        Page<OrderStep> page = orderStepManager.search(query);
        orderSteps = page.getDataList();
        saveRequest("page", PageUtil.conversion(page));
        saveRequest("query", query);
        return LIST;
    }


    /**
     * @return
     */
    public String view() {
        if (id != null) {
            orderStep = orderStepManager.get(id);
        }
        return NONE;
    }


    public List<OrderStep> getOrderSteps() {
        return orderSteps;
    }

    public void setOrderSteps(List<OrderStep> orderSteps) {
        this.orderSteps = orderSteps;
    }

    public OrderStep getOrderStep() {
        return orderStep;
    }

    public void setOrderStep(OrderStep orderStep) {
        this.orderStep = orderStep;
    }

    public OrderStepQuery getQuery() {
        return query;
    }

    public void setQuery(OrderStepQuery query) {
        this.query = query;
    }


}